package com.afkx.oop.demo8;


import java.util.Random;

/**
 * @ClassName 小偷类
 * @Description TODO
 * @Author Kx
 * @Date 2025/3/4 13:52
 * @Version 1.0
 */
public class Thief extends Person{
    public Thief(String name) {
        super(name);
    }

    @Override
    public void open() {
        System.out.println(super.getName() + "可以开门");
    }

    @Override
    public void close() {
        System.out.println(super.getName() + "可以关门");
    }

    /**
     * @description: 小偷盗窃方法
     * @author: Kx
     * @date: 2025/3/4 19:15
     * @param: [door]
     * @return: void
     **/
    public void stealDoor(Door door){
        String name = door.getName();
        // 创建随机数对象
        Random random = new Random();
        // 获取随机布尔值
        boolean aBoolean = random.nextBoolean();
        if(door instanceof Bell){
            ((Bell) door).ring();
            if(aBoolean){
                System.out.println("小偷盗窃" + name + "成功");
            }else {
                System.out.println("小偷盗窃" + name + "失败");
            }
        } else {
            // 没有防盗功能直接偷
            System.out.println("小偷盗窃" + name + "成功");
        }
    }

    public void stealCar(Car car){
        String name = car.getName();

        // 创建随机数对象
        Random random = new Random();
        // 获取随机布尔值
        boolean aBoolean = random.nextBoolean();
        if(car instanceof Bell){
            ((Bell) car).ring();
            if(aBoolean){
                System.out.println("小偷盗窃" + name + "成功");
            }else {
                System.out.println("小偷盗窃" + name + "失败");
            }
        } else {
            // 没有防盗功能直接偷
            System.out.println("小偷盗窃" + name + "成功");
        }
    }
}
